package com.ssm.controller;


import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * The base Spring MVC controller. Used to provide common functionality to all controllers.
 * 
 * @author Mularien
 */
public class BaseController {
    /**
     * Gets the current request's {@link Authentication} information and returns it.
     *
     * @return Authentication for current request
     */
    protected Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

/*    @ModelAttribute("showLoginLink")
    public boolean getShowLoginLink() {
        for (GrantedAuthority authority : getAuthentication().getAuthorities()) {
            if(authority.getAuthority().equals("ROLE_ADMIN")) {
                return false;
            }
        }
        return true;
    }*/

    /**
     * 用来显示当前线上用户数量
     * 当security关闭session后，该方法不适用
     *
     * @return
     */
    /*@Autowired
    SessionRegistry sessionRegistry;//

    @ModelAttribute("numUsers")
    public int getNumberOfUsers() {
        return sessionRegistry.getAllPrincipals().size();
    }*/

}
